// pages/DetailsOfRefund/DetailsOfRefund.js
var http = require('../../utils/http.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showView: true,  //隐藏是展示
    applyTime: '',  //申请时间
    applyType: 1,  //申请类型:1,仅退款,2退款退货
    goodsNum: '',  //退货数量
    handelTime: '',  //卖家处理时间
    orderAmount: '',  //订单总金额
    orderItems: {},  //订单项 
    refundAmount: '',  //退款金额
    refundDelivery: [],  //收货地址对象
    refundId: '',  //记录ID
    refundTime: '',  //退款时间
    returnMoneySts: 1, //处理退款状态:(1.买家申请 2.卖家接受 3.买家发货 4.卖家收货 5.退款成功 6.买家撤回申请 7.商家拒绝 -1.退款关闭)
    updateTime: '',  //更新时间
    refundSn: '',  //退款编号
    rejectMessage: '',  //拒绝理由
    buyerReason: '',  //退款原因



  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      refundSn: options.refundSn
    });
    //获取退款申请详情
    this.getRefundDetail()
  },

  /**
   * 更多说明&收起
   */
  onChangeShowState: function () {
    var that = this;
    that.setData({
      showView: (!that.data.showView)
    })
  },


  /**
   * 获取退款申请详情
   */
  getRefundDetail: function(e) {
    var ths = this;
    // wx.showLoading({})
    var params = {
      url: "/p/orderRefund/info",
      method: "GET",
      data:{
        refundSn: this.data.refundSn  //退款编号
      },
      callBack: function (res) {
        ths.setData({
          applyTime: res.applyTime,  //申请时间
          applyType: res.applyType,  //申请类型:1,仅退款,2退款退货
          goodsNum: res.goodsNum,  //退货数量
          handelTime: res.handelTime,  //卖家处理时间
          orderAmount: res.orderAmount,  //订单总金额
          orderItems: res.orderItems,  //订单项 
          refundSn: res.refundSn,  //退款编号
          refundAmount: res.refundAmount,  //退款金额
          refundDelivery: res.refundDelivery,  //收货地址对象
          refundId: res.refundId,  //记录ID
          refundTime: res.refundTime,  //退款时间
          returnMoneySts: res.returnMoneySts, //处理退款状态:(1.买家申请 2.卖家接受 3.买家发货 4.卖家收货 5.退款成功 6.买家撤回申请 7.商家拒绝 -1.退款关闭)
          updateTime: res.updateTime,  //更新时间
          rejectMessage: res.rejectMessage,  //拒绝理由
          buyerReason: res.buyerReason, //退款原因
        })
        wx.hideLoading();
      }
    };
    http.request(params);
  },

  /**
   * 撤销退货退款申请
   */
  cancelApplication: function (e) {
    console.log('撤销申请')
    wx.showModal({
      title: '撤销',
      content: '确定要撤销本次申请？',
      success:  (res) => {
        if (res.confirm) {
          wx.showLoading({})
          var params = {
            url: "/p/orderRefund/cancel",
            method: "PUT",
            data: this.data.refundSn,  //退款订单编号
            callBack: function (res) {
              wx.hideLoading();
              wx.navigateTo({
                url: '/pages/afterSales/afterSales',
              })
            }
          };
          http.request(params);
        } else {
          console.log('取消')
        }
      }
    })
    
  },


  /**
   * 跳转修改退款申请
   */
  // toAlterRefundApply: function (e) {
  //   var refundSn = e.currentTarget.dataset.refundsn;
  //   console.log(e.currentTarget.dataset.refundsn)
  //   wx.navigateTo({
  //     url: '/pages/applyRefund/applyRefund?refundSn=' + refundSn,
  //   })
  // },


  /**
   * 填写物流信息
   */
  toLogisticsPage:function (e) {
    var refundSn = e.currentTarget.dataset.refundsn;
    console.log(e.currentTarget.dataset.refundsn)
    wx.navigateTo({
      url: '/pages/writeReturnLogistics/writeReturnLogistics?refundSn=' + refundSn,
    })
 },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})